package com.oocl.o2o.client.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oocl.o2o.client.entity.Food;
import com.oocl.o2o.client.entity.Merchant;
import com.oocl.o2o.client.service.FoodService;

/**
 * @description: 
 * @author  XIEMI2
 * @date Aug 13, 2017 9:52:35 AM
 * @version 1.0
 */
@Controller
public class FoodController {

	@Resource
	private FoodService foodService;
	
	
	
	
	@GetMapping("/{merchantName}/foods")
	private String getFoodsByMerchantName(@PathVariable("merchantName") String merchantName, HttpServletRequest request, HttpSession session){
		List<Food> foods = new ArrayList<Food>();
		if(merchantName.equals("all")){
			foods = foodService.findAll();
		}else{
			foods = foodService.findByMerchantName(merchantName);
		}
		session.setAttribute("currentMerchantName", merchantName);
		request.setAttribute("merchantFoods", foods);
		return "view/showFoodByUname";
	}
	
	@ResponseBody
	@GetMapping("/foodName/{keyWord}")
	public List<Food> getFoodsByKewWord(@PathVariable("keyWord") String keyWord){
		return foodService.findByFoodKeyWord(keyWord);			
	}
	
	
	
	
}


